import { ApiProperty, PartialType } from "@nestjs/swagger";
import { IsArray, IsEnum, IsNumber, IsNumberString, IsOptional, IsString, Length } from "class-validator";
import { BaseInfoDto, PaginationDto } from "src/common/dto/index.dto";
import { USER_SEX } from "src/common/enum/user";

export class CreateUserDto extends BaseInfoDto {
    @ApiProperty({ required: false,description:'部门ids' })
    @IsOptional()
    @IsArray()
    deptIds?: number[];

    @ApiProperty({ required: false })
    @IsOptional()
    @Length(0, 50)
    email: string;

    @ApiProperty({ required: true })
    @IsString()
    @Length(0, 30)
    nickName: string;

    @ApiProperty({ required: true })
    @IsString()
    @Length(0, 30)
    userName: string;

    @ApiProperty({ required: true })
    @IsString()
    @Length(0, 200)
    password: string;

    @ApiProperty({ required: true })
    @IsOptional()
    @IsString()
    phone?: string;

    @ApiProperty({ required: false })
    @IsOptional()
    @IsArray()
    postIds?: number[];

    @ApiProperty({ required: false })
    @IsOptional()
    @IsArray()
    roleIds?: number[];

    @ApiProperty({ required: false })
    @IsOptional()
    @IsString()
    @IsEnum(USER_SEX)
    sex?: string;
}

export class UpdateUserDto extends PartialType(CreateUserDto) {
    @ApiProperty({
        required: true
    })
    @IsNumber()
    id: number
}

export class ListUserDto extends PaginationDto {
    @ApiProperty({ required: false })
    @IsOptional()
    @IsNumberString()
    roleId?: number;

    @ApiProperty({ required: false })
    @IsOptional()
    @IsNumberString()
    deptId?: number;

    @ApiProperty({ required: false })
    @IsOptional()
    @IsNumberString()
    postId?: number;

    @ApiProperty({ required: false })
    @IsOptional()
    @IsString()
    @Length(0, 30)
    nickName?: string;

    @ApiProperty({ required: false })
    @IsOptional()
    @IsString()
    @Length(0, 30)
    userName?: string;

    @ApiProperty({ required: false })
    @IsOptional()
    @IsString()
    phone?: string;

    @ApiProperty({ required: false })
    @IsOptional()
    @IsNumberString()
    status?: number;
}

export class DeleteUserDto {
    @ApiProperty({
        required: true
    })
    @IsArray()
    ids: number[]
}

export class ResetPwdDto {
    @ApiProperty({
        required: true
    })
    @IsNumber()
    id: number

    @ApiProperty({
        required: true
    })
    @IsNumberString()
    password: string
}
